package com.zdgk.core.control.config;

import cn.hutool.core.util.StrUtil;
import com.zdgk.core.web.entity.ConfigInfo;
import com.zdgk.core.web.mapper.ConfigInfoMapper;
import lombok.Data;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.List;

@Data
public class MqttConfigInfo {
    private String mqttHost;
    private String mqttClientId;
    private String mqttUsername;
    private String mqttPassword;
    private String mqttUploadTopic;
    private String mqttReceivedTopic;


    public void initConfigInfo(ConfigInfoMapper mapper) {
        List<ConfigInfo> configInfoList = mapper.selectList(null);
        configInfoList.forEach(configInfo -> {
            String configValue = configInfo.getConfigValue();
            switch (configInfo.getConfigKey()) {
                case "mqtt-host":
                    mqttHost = configValue;
                    break;
                case "mqtt-client-id":
                    mqttClientId = configValue;
                    break;
                case "mqtt-username":
                    mqttUsername = configValue;
                    break;
                case "mqtt-password":
                    mqttPassword = configValue;
                    break;
                case "mqtt-upload-topic":
                    mqttUploadTopic = configValue;
                    break;
                case "mqtt-received-topic":
                    mqttReceivedTopic = configValue;
                    break;
                default:
                    break;
            }

        });
    }

}
